﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Text;
using System.Web.Services;

using CE.Database;
using CE.Mail;
using CE.Global;
using CE.CarInsurance;
using CE.User;
using CE.Security;


public partial class car_insurance_car_not_found : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            divCallMe.Visible = true;
            divCallMeMessage.Visible = false;
            if (Request.QueryString["sent"] != null && Request.QueryString["sent"].ToString() != string.Empty && Request.QueryString["sent"].ToString() == "1")
            {
                divCallMeMessage.Visible = true;
                divCallMe.Visible = false;
            }
            LoadTitles();
            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "');DefaultName(this, event);");
            txtName.Attributes.Add("onfocus", "ClearText(this, event);");
            txtEmail.Attributes.Add("onblur", "RemoveSpace(this);ShowValidationEffectTwo('" + txtEmail.ClientID + "','" + rfvEmail.ClientID + "','" + revEmail.ClientID + "');DefaultEmail(this, event);");
            txtEmail.Attributes.Add("onfocus", "ClearText(this, event);");
            txtMobile.Attributes.Add("onblur", "RemoveSpace(this);ShowValidationEffectTwo('" + txtMobile.ClientID + "','" + rfvMobile.ClientID + "','" + revMobile.ClientID + "');DefaultPhone(this, event);");
            txtMobile.Attributes.Add("onfocus", "ClearText(this, event);");

            //if (Session[CE.Global.General.IsAcceptTC] != null)
            //{
            //    chkAggrement.Checked = true;
            //    if (Session[CE.Global.General.IsAcceptTC].ToString() != "1")
            //    {
            //        chkAggrement.Checked = false;
            //    }
            //}
            HttpCookie _cookie = Request.Cookies.Get("GGMobileQuote");
            if (_cookie != null)
            {
                txtEmail.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerEmail"), true);
                txtName.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerName"), true);
                txtMobile.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerMobile"), true);
                string _isaccept = "FALSE";
                string[] _CK = _cookie.Value.Split('&');
                if (_CK.Length > 3)
                {
                    _isaccept = MySecurity.Decrypt(_cookie.Values.Get("IsAccept"), true);
                    if (_isaccept != null && _isaccept == "TRUE")
                    {
                        hdnIsAceept.Value = "TRUE";
                    }
                }
                if (txtName.Text.Trim() != string.Empty && txtEmail.Text.Trim() != string.Empty && txtMobile.Text.Trim() != string.Empty)
                {
                    GetUserDetails(Server.HtmlEncode(txtEmail.Text.Trim().ToLower()));
                    //if (Session[CE.Global.General.IsAcceptTC] != null)
                    //{
                    //    chkAggrement.Checked = true;
                    //    if (Session[CE.Global.General.IsAcceptTC].ToString() != "1")
                    //    {
                    //        chkAggrement.Checked = false;
                    //    }
                    //}
                }
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            ChangeValidationEffectServerSide("callme");
            Page.Validate("callme");
            if (Page.IsValid)
            {
                divLoading.Attributes.Add("style", "");
                if (txtMobile.Text.Trim().Length == 10)
                {
                    Int64 _userId = 0;
                    Int64 _carId = 0;
                    Int64 _ProviderId = 0;

                    Account _useraccount = new Account();
                    AccountDB _useraccountdb = new AccountDB();

                    _useraccount = _useraccountdb.GetUserAccount(EmailAddress, 400);
                    if (_useraccount != null && _useraccount.CEID > 0)
                    {
                        _userId = _useraccount.CEID;
                        Profile _userprofile = new Profile();
                        ProfileDB _userprofiledb = new ProfileDB();

                        Contact _usercontact = new Contact();
                        ContactDB _usercontactdb = new ContactDB();

                        Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                        _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);

                        if (_userprofile != null && _userprofile.ProfileId > 0)
                        {
                            _userprofile.SurName = string.Empty;
                            _userprofile.FirstName = Server.HtmlEncode(txtName.Text);
                            _userprofile.IsAcceptTC = chkAggrement.Checked;
                            _userprofiledb.Insert(_userprofile);
                        }
                        _usercontact = _usercontactdb.GetContact(_useraccount.CEID);
                        if (_usercontact != null && _usercontact.ContactId > 0)
                        {
                            _usercontact.Mobile = txtMobile.Text.Trim();
                            _usercontactdb.Insert(_usercontact);
                        }
                        Session[CE.Global.General.UserId] = _useraccount.CEID;
                        Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                        Session[CE.Global.General.UserEmail] = _useraccount.Email;
                        Session[CE.Global.General.UserName] = _userprofile.FirstName;
                        Session[CE.Global.General.IsAcceptTC] = "0";
                        if (_userprofile.IsAcceptTC == true)
                        {
                            Session[CE.Global.General.IsAcceptTC] = "1";
                        }
                        Session[CE.Global.General.UserPhoneNo] = _usercontact.Mobile;
                        _useraccount = null;
                        _useraccountdb = null;
                        _userprofile = null;
                        _userprofiledb = null;
                        _usercontact = null;
                        _usercontactdb = null;
                    }
                    else
                    {
                        if (UpdateProfile(_userId, 0) > 0)
                        {
                            SendMailToUser(EmailAddress, Name, MobileNumber);

                            Session["CLASSTYPE"] = "1";
                            _userId = Convert.ToInt64(Session[General.UserId].ToString());
                        }
                    }
                    SetCookies();

                    if (Session[General.UserId] != null)
                    {
                        if (!Int64.TryParse(Session[General.UserId].ToString(), out _userId))
                        {
                            _userId = 0;
                        }
                    }

                    if (IsValid)
                    {
                        #region Call Me
                        string _message = "";
                        string _title = "";

                        _message = "Customer Name: " + Server.HtmlEncode(txtName.Text);
                        _title = "<mobile> Car not found - Call me now - Request by " + Server.HtmlEncode(txtName.Text);

                        Int64 _result = 0;
                        ContactUser _cu = new ContactUser();
                        ContactUserDB _cudb = new ContactUserDB();
                        string strInsType = "";
                        if (Request.Params["instype"] != null && Request.Params["instype"].ToString() != string.Empty)
                        {
                            strInsType = Request.Params["instype"].ToString();
                        }
                        if (strInsType == "10")
                        {
                            strInsType = "1";
                        }
                        else if (strInsType == "11")
                        {
                            strInsType = "1+";
                        }
                        else if (strInsType == "21")
                        {
                            strInsType = "2+";
                        }
                        else if (strInsType == "30")
                        {
                            strInsType = "3+";
                        }
                        else if (strInsType == "31")
                        {
                            strInsType = "3+";
                        }

                        _cu.InsuranceType = "CI-" + strInsType;
                        _cu.ProductId = _carId;
                        _cu.RefCEUserId = _userId;
                        _cu.ProviderCompanyId = _ProviderId;
                        _cu.ContactNo = Server.HtmlEncode(txtMobile.Text);
                        _cu.FullName = Server.HtmlEncode(txtName.Text);
                        _cu.CallTime = Convert.ToInt16(ddlCallMeTime.Text);

                        if (Request.Params["spc"] != null)
                        {
                            if (Request.Params["spc"].ToString() == "1")
                            {
                                _cu.Info1 = "GG Promotion";
                            }
                        }
                        _cu.Info2 = "CARNOTFOUND";
                        _cu.Info3 = "MOBILE";

                        _result = _cudb.Insert(_cu);

                        if (_result > 0)
                        {
                            #region Hide Call me email sending - Sakthi on 11 Dec 2014
                            //_message += "<br/><br/>Email : " + txtEmail.Text;
                            //_message += "<br/><br/>Contact No : " + txtMobile.Text.Trim();
                            //_message += "<br/><br/>Call Time : " + ddlCallMeTime.SelectedItem.Text;
                            //string _emailList = ConfigurationManager.AppSettings["Mobile.TH.CICallMeReceiver"].ToString();
                            //MyMailManager.SendNotification(_emailList, _title, _message);
                            #endregion
                        }

                        #endregion
                        Response.Redirect("car-not-found.aspx?sent=1");
                    }
                }
            }
            else
            {
                divLoading.Attributes.Add("style", "none");
            }
        }
        catch (Exception ex)
        {
        }
    }

    private void LoadTitles()
    {
        lblCallUs.Text = Resources.CarMenu.Callus + " ";
        lblApplicationTitle.Text = Resources.CarMenu.OR + " " + Resources.CarMenu.CallYouBack;
        lblThanksTitle.Text = Resources.CarMenu.ThankYou;
        lblMessage1.Text = Resources.CarMenu.CallMeMessage;
        lblMessage2.Text = Resources.CarMenu.HotLineMessage;
        btnSubmit.Text = Resources.ProposalForm.Submit;
        lblAggrement.Text = Resources.UserMessage.Aggrement;
        //ibtnBack.ImageUrl = Resources.CarMenu.ButtonBackUrl;
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        txtName.Text = HttpUtility.HtmlEncode(txtName.Text.Trim());
        txtEmail.Text = HttpUtility.HtmlEncode(txtEmail.Text);
        txtMobile.Text = HttpUtility.HtmlEncode(txtMobile.Text);

        #region CallMeTime
        //CallMeTime
        if (rfvCallMeTime.Enabled && rfvCallMeTime.ValidationGroup == strValidationGroup)
        {
            rfvCallMeTime.Validate();
            if (rfvCallMeTime.IsValid == false)
            {
                ddlCallMeTime.ControlStyle.CssClass = "dropdown-fields validationError";
            }
            else
            {
                ddlCallMeTime.ControlStyle.CssClass = "dropdown-fields";
            }
        }
        else
        {
            ddlCallMeTime.ControlStyle.CssClass = "dropdown-fields";
        }
        #endregion

        #region User
        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "text-fields";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "text-fields";
        }

        //Email
        if (rfvEmail.Enabled && rfvEmail.ValidationGroup == strValidationGroup)
        {
            rfvEmail.Validate();
            if (rfvEmail.IsValid == false)
            {
                txtEmail.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtEmail.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "text-fields";
        }

        if (revEmail.Enabled && revEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail.IsValid)
            {
                revEmail.Validate();
                if (revEmail.IsValid == false)
                {
                    txtEmail.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtEmail.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "text-fields";
        }

        //Mobile No
        if (rfvMobile.Enabled && rfvMobile.ValidationGroup == strValidationGroup)
        {
            rfvMobile.Validate();
            if (rfvMobile.IsValid == false)
            {
                txtMobile.ControlStyle.CssClass = "text-fields validationError";
            }
            else
            {
                txtMobile.ControlStyle.CssClass = "text-fields";
            }
        }
        else
        {
            txtMobile.ControlStyle.CssClass = "text-fields";
        }

        if (revMobile.Enabled && revMobile.ValidationGroup == strValidationGroup)
        {
            if (rfvMobile.IsValid)
            {
                revMobile.Validate();
                if (revMobile.IsValid == false)
                {
                    txtMobile.ControlStyle.CssClass = "text-fields validationError";
                }
                else
                {
                    txtMobile.ControlStyle.CssClass = "text-fields";
                }
            }
        }
        else
        {
            txtMobile.ControlStyle.CssClass = "text-fields";
        }
        #endregion
    }

    private Int64 SaveNewCustomer_Old()
    {
        #region New Customer
        Int64 _retVal = 0;
        bool _isEmailExist = false;

        Account _useraccount = new Account();
        AccountDB _useraccountdb = new AccountDB();

        Profile _userprofile = new Profile();
        ProfileDB _userprofiledb = new ProfileDB();
        Contact _contact = new Contact();
        ContactDB _contactdb = new ContactDB();

        if (_useraccountdb.IsAlreadyExist(txtEmail.Text.Trim(), Convert.ToInt32(CE.Global.General.CEUserType.Customer)))
        {
            _isEmailExist = true;

            _useraccount = _useraccountdb.GetUserAccount(txtEmail.Text.Trim(), 400);

            if (_useraccount != null && _useraccount.CEID > 0)
            {
                _contact = _contactdb.GetContact(_useraccount.CEID);
                //if (_contact.Mobile == txtUserMobile.Text.Trim())
                //{
                //UpdateProfile(_useraccount.CEID, 0);

                //_profile = _profiledb.GetProfile(_useraccount.CEID);
                Session[CE.Global.General.UserId] = _useraccount.CEID;
                Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                Session[CE.Global.General.UserEmail] = _useraccount.Email;
                Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);
                if (_userprofile != null && _userprofile.ProfileId > 0)
                {
                    if (_userprofile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _userprofile.SurName;
                    }
                }
                _retVal = _useraccount.CEID;
                //}
                //else
                //{
                //    _retVal = 0;
                //}
            }
            else
            {
                _retVal = 0;
            }
        }

        if (_retVal == 0 && _isEmailExist == false)
        {
            long _result = -1;
            _useraccount.Email = txtEmail.Text.ToLower();

            string _authcode = txtMobile.Text;
            _useraccount.AuthCode = _authcode;

            _useraccount.UserId = "CEUSERAUTOIDMOBILECI";
            _useraccount.UserTypeId = Convert.ToInt32(CE.Global.General.CEUserType.Customer);
            _useraccount.IsAcceptTC = false;
            _useraccount.Status = true;
            _useraccount.RefCEUserID = -1;

            _result = _useraccountdb.Insert(_useraccount);
            _useraccount.CEID = _result;
            _retVal = _useraccount.CEID;

            if (_result > 0)
            {
                _userprofile.Salutation = "";
                _userprofile.FirstName = Server.HtmlEncode(txtName.Text);
                _userprofile.SurName = "";

                DateTime _dtDOB = new DateTime(1900, 1, 1);
                _userprofile.DOB = _dtDOB;

                _userprofile.DOB = General.GetUTCDateTime().AddYears(-25);
                _userprofile.Gender = 'M';

                _userprofile.Occupation = 140;
                _userprofile.Status = "Complete";
                _userprofile.RefCEUserId = _useraccount.CEID;
                _userprofile.IsAcceptTC = true;
                _result = _userprofiledb.Insert(_userprofile);

                _contact.Email = _useraccount.Email;
                _contact.Mobile = txtMobile.Text;

                _contact.Status = true;
                _contact.RefCEUserId = _useraccount.CEID;
                _result = _contactdb.Insert(_contact);

                if (_result > 0)
                {
                    Session[CE.Global.General.UserId] = _useraccount.CEID;
                    Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                    Session[CE.Global.General.UserEmail] = _useraccount.Email;
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                    Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                    if (_userprofile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _userprofile.SurName;
                    }

                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";

                    SendMailToUser(_useraccount.Email, Session[CE.Global.General.UserName].ToString(), _contact.Mobile);
                }

            }
        }

        return _retVal;
        #endregion
    }

    private Int64 UpdateProfile(Int64 UserId, Int64 CarId)
    {
        Int64 _retValue = 0;

        if (UserId != 0)
        {
            Profile _profile = new Profile();
            ProfileDB _profiledb = new ProfileDB();

            Contact _contact = new Contact();
            ContactDB _contactdb = new ContactDB();

            _profile = _profiledb.GetProfile(UserId);
            _contact = _contactdb.GetContact(UserId);

            if (_profile != null)
            {
                #region Update Profile

                _profile.Salutation = "";
                _profile.FirstName = txtName.Text;
                _profile.SurName = "";
                _profile.DOB = General.GetUTCDateTime().AddYears(-25);
                _profile.Gender = 'M';

                _profile.MaritalStatus = -1;
                _profile.JobNature = "";
                _profile.Occupation = 140;
                _profile.YearDriveSg = 0;
                _profile.Status = "Complete";
                _profile.IsAcceptTC = chkAggrement.Checked;

                _retValue = _profiledb.Insert(_profile);

                if (_retValue > 0 && _contact != null)
                {
                    _contact.Mobile = txtMobile.Text;
                    _contact.Status = true;

                    _retValue = _contactdb.Insert(_contact);
                }
                else
                {
                }

                if (_retValue > 0)
                {
                    if (_profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = _profile.FirstName + " " + _profile.SurName;
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = _profile.SurName;
                    }
                    Session[CE.Global.General.IsAcceptTC] = "0";
                    if (_profile.IsAcceptTC == true)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "1";
                    }
                    Session[General.UserPhoneNo] = txtMobile.Text;
                    Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                }

                _profile = null;
                _contact = null;
                #endregion
            }
        }
        else
        {
            _retValue = SaveNewCustomer();
            UserId = _retValue;
        }
        return _retValue;
    }

    private Int64 SaveNewCustomer()
    {
        #region New Customer
        Int64 _retVal = 0;
        if (Page.IsValid)
        {
            Account _useraccount = new Account();
            AccountDB _useraccountdb = new AccountDB();

            Profile _userprofile = new Profile();
            ProfileDB _userprofiledb = new ProfileDB();

            Contact _contact = new Contact();
            ContactDB _contactdb = new ContactDB();

            _useraccount = _useraccountdb.GetUserAccount(txtEmail.Text.Trim(), 400);
            if (_useraccount != null)
            {
                if (_useraccount.CEID > 0)
                {
                    _retVal = _useraccount.CEID;
                    _contact = _contactdb.GetContact(_useraccount.CEID);
                    Session[CE.Global.General.UserId] = _useraccount.CEID;
                    Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                    Session[CE.Global.General.UserEmail] = _useraccount.Email;
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                    Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                    _userprofile = _userprofiledb.GetProfile(_useraccount.CEID);
                    if (_userprofile != null && _userprofile.ProfileId > 0)
                    {
                        if (_userprofile.FirstName != string.Empty)
                        {
                            Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                        }
                        else
                        {
                            Session[CE.Global.General.UserName] = _userprofile.SurName;
                        }
                    }
                }
            }
            else
            {

                long _result = -1;
                _useraccount = new Account();
                _useraccount.Email = txtEmail.Text.Trim().ToLower();
                string _authcode = txtMobile.Text.Trim();
                _useraccount.AuthCode = _authcode;
                _useraccount.UserId = "CEUSERAUTOIDMOBILECI";
                _useraccount.UserTypeId = 400;
                _useraccount.IsAcceptTC = false;
                _useraccount.Status = true;
                _useraccount.RefCEUserID = -1;
                _result = _useraccountdb.Insert(_useraccount);
                _useraccount.CEID = _result;
                _retVal = _useraccount.CEID;
                if (_result > 0)
                {
                    _userprofile.Salutation = "";
                    _userprofile.FirstName = Server.HtmlEncode(txtName.Text);
                    _userprofile.SurName = "";
                    DateTime dteDOB = new DateTime(1995, 1, 1);
                    _userprofile.DOB = dteDOB;
                    _userprofile.Gender = 'M';

                    _userprofile.Occupation = 140;
                    _userprofile.Status = "Complete";
                    _userprofile.RefCEUserId = _useraccount.CEID;
                    _userprofile.IsAcceptTC = chkAggrement.Checked;
                    _result = _userprofiledb.Insert(_userprofile);

                    _contact.Email = _useraccount.Email;
                    _contact.Mobile = txtMobile.Text.Trim();

                    _contact.Status = true;
                    _contact.RefCEUserId = _useraccount.CEID;
                    _result = _contactdb.Insert(_contact);

                    if (_result > 0)
                    {
                        Session[CE.Global.General.UserId] = _useraccount.CEID;
                        Session[CE.Global.General.UserTypeId] = _useraccount.UserTypeId;
                        Session[CE.Global.General.UserEmail] = _useraccount.Email;
                        Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                        Session[CE.Global.General.StartTime] = General.GetUTCDateTime().ToString();
                        if (_userprofile.FirstName != string.Empty)
                        {
                            Session[CE.Global.General.UserName] = _userprofile.FirstName + " " + _userprofile.SurName;
                        }
                        else
                        {
                            Session[CE.Global.General.UserName] = _userprofile.SurName;
                        }
                        Session[CE.Global.General.UserProfileAndContactComplete] = "1";
                        Session[CE.Global.General.IsAcceptTC] = "0";
                        if (_userprofile.IsAcceptTC == true)
                        {
                            Session[CE.Global.General.IsAcceptTC] = "1";
                        }
                    }

                }

            }
        }
        else
        {
            _retVal = 0;
        }

        return _retVal;
        #endregion
    }

    private bool SendMailToUser(string EmailAddress, string UserName, string AuthCode)
    {
        bool _retVal = false;
        _retVal = CE.Email.Welcome.SendMail(EmailAddress, UserName, AuthCode);
        return _retVal;
    }

    private string EmailAddress
    {
        get { return txtEmail.Text.Trim(); }
    }

    private string MobileNumber
    {
        get { return txtMobile.Text.Trim(); }
    }

    private string Name
    {
        get { return txtName.Text.Trim(); }
    }

    private void SetCookies()
    {
        try
        {
            string _isAccept = "FALSE";
            if (hdnIsAceept.Value == "TRUE")
            {
                _isAccept = "TRUE";
            }
            HttpCookie _cookie = new HttpCookie("GGMobileQuote");
            _cookie.Values.Add("CustomerName", MySecurity.Encrypt(txtName.Text, true));
            _cookie.Values.Add("CustomerEmail", MySecurity.Encrypt(txtEmail.Text, true));
            _cookie.Values.Add("CustomerMobile", MySecurity.Encrypt(txtMobile.Text, true));
            _cookie.Values.Add("IsAccept", MySecurity.Encrypt(_isAccept, true));
            _cookie.Expires = DateTime.Now.AddDays(90);
            Response.Cookies.Add(_cookie);
        }
        catch (Exception Ex)
        {
            Ex = null;
        }
    }

    private void GetCookies()
    {
        try
        {
            HttpCookie _cookie = Request.Cookies.Get("GGMobileQuote");
            if (_cookie != null)
            {
                txtName.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerName"), true);
                txtEmail.Text = MySecurity.Decrypt(_cookie.Values.Get("CustomerEmail"), true);
                string _mobile = MySecurity.Decrypt(_cookie.Values.Get("CustomerMobile"), true);
                txtMobile.Text = _mobile;
                string _isaccept = "FALSE";
                string[] _CK = _cookie.Value.Split('&');
                if (_CK.Length > 3)
                {
                    _isaccept = MySecurity.Decrypt(_cookie.Values.Get("IsAccept"), true);
                    if (_isaccept != null && _isaccept == "TRUE")
                    {
                        hdnIsAceept.Value = "TRUE";
                    }
                }
            }
        }
        catch (Exception Ex)
        {
            Ex = null;
        }
    }

    private void GetUserDetails(string CustomerEmail)
    {
        try
        {
            AccountDB _accountdb = new AccountDB();
            Account _account = _accountdb.GetUserAccount(CustomerEmail.ToLower(), 400);
            if (_account != null)
            {
                Session[CE.Global.General.UserId] = _account.CEID;
                Session[CE.Global.General.UserTypeId] = _account.UserTypeId;
                Session[CE.Global.General.UserEmail] = _account.Email;

                Profile _profile = new Profile();
                ProfileDB _profiledb = new ProfileDB();
                Contact _contact = new Contact();
                ContactDB _contactdb = new ContactDB();

                _contact = _contactdb.GetContact(_account.CEID);
                _profile = _profiledb.GetProfile(_account.CEID);

                if (_contact != null)
                {
                    Session[CE.Global.General.UserPhoneNo] = _contact.Mobile;
                }
                else
                {
                    Session[CE.Global.General.UserPhoneNo] = null;
                }
                if (_profile != null)
                {
                    if (_profile.FirstName != null && _profile.FirstName != string.Empty)
                    {
                        Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.FirstName) + " " + Server.HtmlDecode(_profile.SurName);
                    }
                    else
                    {
                        Session[CE.Global.General.UserName] = Server.HtmlDecode(_profile.SurName);
                    }
                    if (_profile.IsAcceptTC != null)
                    {
                        Session[CE.Global.General.IsAcceptTC] = "0";
                        if (_profile.IsAcceptTC == true)
                        {
                            Session[CE.Global.General.IsAcceptTC] = "1";
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
    }

}
